<!--
@fucntion: 视频信息
-->
<template>
<div class="module-basic-VideoUpload">
  <el-row style="height:100%;">
    <el-col style="height:100%;">
      <table-panel :name="'视频信息'" 
      :columns="VideoUploadColumns" 
      :tableData="VideoUploadData" 
      :showRowNumber="false" 
      :multiSelection="true"
      :inputLabelSearchMode="true"
      :canCreate="authorities.create" 
      :canEdit="authorities.edit" 
      :canDelete="authorities.delete"
      :canExport="authorities.export"
      :currentPage="VideoUploadCurrentPage" 
      :totalNum="VideoUploadTotalNum" 
      @page-change="onPageChange('VideoUpload',$event)" 
      :pageSize="pageSize"
      @table-searching="onSearching('VideoUpload',$event)"
      @table-create="onCreate('VideoUpload',$event)" 
      @table-edit="onEdit('VideoUpload', $event)"
      @table-delete="onDelete('VideoUpload',$event)" 
      @table-export="onExport('VideoUpload',$event)"
      @selection-change="onSelectionChange('VideoUpload',$event)">
      </table-panel>
    </el-col>
  </el-row>
  <VideoUpload-dlg 
  :VideoUploadRecord="VideoUploadRecord" 
  :VideoUploadRules="VideoUploadRules" 
  :VideoUploadDlgVisible="VideoUploadDlgVisible" 
  :hasResetBtn="true"
  @upload-success1="handleAvatarSuccess1" 
  @upload-success2="handleAvatarSuccess2" 
  @close="VideoUploadDlgVisible=false" 
  @confirm="onConfirm('VideoUpload')" 
  @reset-password="onResetPassword('VideoUpload')">
  </VideoUpload-dlg>
</div>
</template>

<script>
import TablePanel from "@/components/basic/TablePanel";//一个简单的增删查改表格
import {
  formModelInitFromTable,
  formRulesInitFromTable
} from "@/utils/formutils.js";//从表格列变换到表单的一些工具

import VideoDlg from "@/modules/upload/increase/VideoDlg";//新增记录

//meta info
var VideoUpload = "VideoUpload"; // 表格名称
var columnsAttr = "Columns"; // 列
var dataAttr = "Data"; // 数据
var selectionAttr = "Selection"; // 选中
var dlgVisibleAttr = "DlgVisible"; // 对话框
var formAttr = "Form";
var recordAttr = "Record"; // 表单模型
var rulesAttr = "Rules"; // 表单验证
var curPageAttr = "CurrentPage";// 分页-当前页
var totalNumAttr = "TotalNum";// 分页-总数
var qParamAttr = "QueryParams";// 查询参数

// 视频信息-列
var VideoUploadColumns = [
  {
    prop: "SPMSBH",
    label: "视频描述编号",
    outOfSearch:true,
    hidden: true,
  },
  {
    prop: "SPMSLX",
    label: "视频描述类型",
    hidden: true,
  },
    {
    prop: "SPMSMC",
    label: "视频名称",
    rules: [{
      required: true,
      message: "必填", 
      trigger: "blur"
    },{ 
      max: 30, 
      message: "不超过30个字符", 
      trigger: 'blur' 
    }]
  },
    {
    prop: "SPGJZ",
    label: "视频关键字",
    hidden: true,
    rules: [{
      required: true,
      message: "必填", 
      trigger: "blur"
    },{ 
      max: 100, 
      message: "不超过100个字符", 
      trigger: 'blur' 
    }]
  },
    {
    prop: "SPMSJJ",
    label: "视频描述简介",
    hidden: true,
    rules: [{
      required: true,
      message: "必填", 
      trigger: "blur"
    },{ 
      max: 200, 
      message: "不超过200个字符", 
      trigger: 'blur' 
    }]
  },
    {
    prop: "SPMSFMTPURL",
    label: "视频描述封面图片URL",
    hidden: true,
    outOfSearch:true,
  },
    {
    prop: "SPMSDJS",
    label: "点击数",
  },
    {
    prop: "SPMSFBSJ",
    label: "发布时间",
    type:"date",
  },
    {
    prop: "SPMSZT",
    label: "状态",
  },
    {
    prop: "SPMSFBR",
    label: "发布人",
  },
//媒体库部分
    {
    prop: "MTKBH",
    label: "媒体库编号",
    hidden: true,
    outOfSearch:true,
  },
    {
    prop: "MSBH",
    label: "描述编号",
    hidden: true,
    outOfSearch:true,
  },
    {
    prop: "MTKPX",
    label: "媒体库排序",
    hidden: true,
    outOfSearch:true,
  },
    {
    prop: "MTKURL",
    label: "媒体库URL",
    hidden: true,
    outOfSearch:true,
  },
    {
    prop: "MTKZT",
    label: "媒体库状态",
    hidden: true,
    outOfSearch:true,
  },
    {
    prop: "MTKSCSJ",
    label: "媒体库上传时间",
    hidden: true,
    type:"date",
    outOfSearch:true,
  },
    {
    prop: "MTKFBR",
    label: "媒体库发布人",
    hidden: true,
    outOfSearch:true,
  },
];

export default {
  name: "VideoUpload",
  components: {
    "table-panel": TablePanel,
    "VideoUpload-dlg":VideoDlg
  },
  methods: {
    onSearching: function(tname, params) {//查询
      var me = this;
      let url = "/api/VideoUpload";// /jcJsxxb   /static/data/VideoUpload.json

      if(url !== "") {
        me[tname+qParamAttr] = {};
        me[tname+qParamAttr] = params;
        if (params.isAccurate) {
          me[tname+qParamAttr] = params.paramPairs;
        } else {
          me[tname+qParamAttr].keywords = params.query;
        }
        me.getRequest(url, me[tname+qParamAttr]).then(resp => {
            if(resp.status == 200) {
              me[tname+dataAttr] = resp.data.data;
              me[tname+totalNumAttr] = resp.data.data.length;
              //me[tname+dataAttr] = resp.data.results;
              //me[tname+totalNumAttr] = resp.data.total;
            }
        });
      }
    },
    onCreate: function(tname) {// 新增
      var me = this;
      me[tname + recordAttr] = formModelInitFromTable(me[tname + columnsAttr]);
      me[tname + recordAttr].SPMSZT = "1"; // 创建时，是否启用选中
      
      me[tname + dlgVisibleAttr] = true;
    },
    onEdit: function(tname, row) {// 编辑
      var me = this;
      me[tname + recordAttr] = row;
      me[tname + dlgVisibleAttr] = true;
    },
    onDelete: function(tname, row) {// 删除
      var me = this;
      me.$confirm("确定删除这条记录吗?", "提示", {
          type: "warning"
      }).then(() => {
          me.deleteRequest(`/api/VideoUpload/${row.SPMSBH}`).then((resp)=>{
            if(resp.status == 200) {
              me.$message.success("删除成功!");
              me.onSearching(VideoUpload,{});// 重新加载表格数据
            }else{
              me.$message.error('删除失败！');
            }
          });
      }).catch(() => {});
    },
    onSelectionChange: function(tname, data) {// 选中改变
      var me = this;
      // 缓存记录，按照编号，查询对应的选中权限节点数组
      me[tname + selectionAttr] = data;
    },
    onExport: function(tname, params) {// 导出
      var me = this;
      me.$message.info("发送导出请求，返回下载路径");
    },
    onPageChange:function(tname,page){// 分页改变
      var me = this;
      let url = "/jcJsxxb";// /jcJsxxb

      if(url !== ""){
        me[tname+curPageAttr] = page;
        me[tname+qParamAttr]["page"] = page;
        me.getRequest(url, me[tname+qParamAttr]).then(resp => {
            if(resp.status == 200) {
              //me[tname+dataAttr] = resp.data.results;
              //me[tname+totalNumAttr] = resp.data.total;
              me[tname+dataAttr] = resp.data.data;
              me[tname+totalNumAttr] = resp.data.data.length;
            }
        });
      }

    },
    onConfirm: function(tname) {// 对话框-确认
      let me = this;
      // 发送请求 /jcJsxxb

      var aData = new Date();

      if(me[VideoUpload + recordAttr].SPMSFBR == ""){
        // 把登陆用户放进YPFBR
        me[VideoUpload + recordAttr].SPMSDJS = 0;
        me[VideoUpload + recordAttr].SPMSFBR = "发布人";
        me[VideoUpload + recordAttr].SPMSFBSJ = aData.getFullYear() + "-" + (aData.getMonth() + 1) + "-" + aData.getDate();
      
        me[VideoUpload + recordAttr].MTKZT = me[VideoUpload + recordAttr].SPMSZT
        me[VideoUpload + recordAttr].MTKSCSJ = me[VideoUpload + recordAttr].SPMSFBSJ
        me[VideoUpload + recordAttr].MTKFBR = me[VideoUpload + recordAttr].SPMSFBR

        me.postRequest("/api/VideoUpload",me[VideoUpload + recordAttr]).then(resp => {
          if (resp.status == 200) {
            me.$message.success("提交成功！");
            //最后，隐藏对话框
            me[tname + dlgVisibleAttr] = false;
            me.onSearching(VideoUpload, {});// 重新查一遍
          } else {
            me.$message.error("服务器发生错误，代码：" + resp.status);
          }
        });
      }else{
        
        me[VideoUpload + recordAttr].MTKZT = me[VideoUpload + recordAttr].SPMSZT
        
        me.postRequest("/api/VideoModify",me[VideoUpload + recordAttr]).then(resp => {
          if (resp.status == 200) {
            me.$message.success("提交成功！");
            //最后，隐藏对话框
            me[tname + dlgVisibleAttr] = false;
            me.onSearching(VideoUpload, {});// 重新查一遍
          } else {
            me.$message.error("服务器发生错误，代码：" + resp.status);
          }
        });
      }
    },
    handleAvatarSuccess1:function(res, file) {//封面图片上传成功之后
      var me = this;
			me[VideoUpload+recordAttr]['SPMSFMTPURL'] = res.path;//生成一个服务器路径，保存起来
      me.imageUrl = URL.createObjectURL(file.raw);// 显示照片
    },
    handleAvatarSuccess2:function(res, file) {//视频上传成功之后
      var me = this;
			me[VideoUpload+recordAttr]['MTKURL'] = res.path;//生成一个服务器路径，保存起来
    },
  },
  data() {
    return {
      authorities:{
        create:true,
        delete:true,
        edit:true,
        search:true,
        export:true
      },// 权限控制
      [VideoUpload + columnsAttr]: VideoUploadColumns, // 表格-列
      [VideoUpload + dataAttr]: [], // 表格的数据
      [VideoUpload + selectionAttr]: [], // 当前选中
      [VideoUpload + dlgVisibleAttr]: false, // 对话框是否可见
      [VideoUpload + recordAttr]: {}, // 表单模型
      [VideoUpload + rulesAttr]: {},// 表单验证
      [VideoUpload + curPageAttr]:1,// 当前页
      [VideoUpload + totalNumAttr]:0,// 总数
      [VideoUpload + qParamAttr]:{},// 查询参数
      pageSize:20,// 每页数量
      
    };
  },
  created: function() {
    var me = this;
    // 添加权限控制
    // me.authorities = me.$route.meta.authorities;

    // 表单模型初始化
    me[VideoUpload + recordAttr] = formModelInitFromTable(me[VideoUpload + columnsAttr]);
    // 表单验证初始化
    me[VideoUpload + rulesAttr] = formRulesInitFromTable(me[VideoUpload + columnsAttr]);

    
    me.onSearching(VideoUpload, {});// 重新查一遍

  }
};
</script>

<style lang="scss">
.module-basic-VideoUpload {
  height: 100%;
}
</style>


